package com.laogao.lesson009.config;

import com.laogao.lesson009.comm.ThreadPoolManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * <b>description</b>： Java进阶、性能优化实战案例100讲，微信公众号:程序员恰恰 <br/>
 * <b>time</b>：2025/2/24 15:16 <br>
 * <b>author</b>：ready lao_gao
 */
//使用 @Configuration(proxyBeanMethods = false) 关闭代理功能,可以避免 Spring 代理机制对动态调整的影响。
//尤其是在配置类简单且没有复杂依赖关系的情况下,可以帮助提高性能
@Configuration(proxyBeanMethods = false)
public class ThreadPoolConfiguration {
    /**
     * 发送邮件用到的线程池
     *
     * @return
     */
    @Bean
    public ThreadPoolTaskExecutor emailThreadPool() {
        return ThreadPoolManager.newThreadPool("emailThreadPool", 10, 20, 1000);
    }

    /**
     * 发送短信用到的线程池
     *
     * @return
     */
    @Bean
    public ThreadPoolTaskExecutor smsThreadPool() {
        return ThreadPoolManager.newThreadPool("smsThreadPool");
    }
}
